<?php
namespace app\wf\controller;
use \think\Db;
use think\Controller;
use \think\Request;
use \think\Session;
use \app\wf\controller\M;
use app\common\controller\DirectoryPageBase;
class HttpHandler extends DirectoryPageBase
{

	public function index($DoMethod)
	{
		//方法
		return $this->$DoMethod();
	}
	public function Login_InitInfo(){
		$array = array( //普通数组
			"EndJSON" => "0",
			"SysName" =>"工作流",
			"SysNo" => "CCFLOW"
			);
		return $array;
	}
	public function Login_Init(){
		$data="ccbpm 准备完毕,欢迎登录,当前小版本号为:20190225";
		return $data;
	}
	public function Login_Submit(){

		$where=[];
		$where['No']=['=',$this->request->post('TB_No')];
		$where['Pass']=['=',$this->request->post('TB_PW')];
		//验证用户是否存在
		$user=Db::table('port_emp')
				->where($where)
				->fetchSql(false)
				->find();

		if(!empty($user)){
			session_start();
			$sid = session_id();

			Db::table('port_emp')
			->where('No', $user['No'])
			->update(['SID' => $sid]);

			Session::set('user',$user);

			return "url@Default.htm?SID=".$sid."&UserNo=".$user['No'];
		}else{
			$data="err@用户名或密码错误";
			return $data;
		}	
	}
	//
	public function LetLogin(){
		$data="登录成功.";
		return $data;
	}
	//退出之后的提示信息
	public function Logout(){
		$data="您已经安全退出,欢迎使用ccbpm.";
		return $data;
	}
	//默认初始化 
	public function Default_Init(){
		$array = array( //普通数组
			"CustomerName" => "驰骋工作流",
			"CustomerNo" =>"CCFlow",
			"EndJSON" => "0",
			"Msg" =>"",
			"OSModel" => "1",
			"RunOnPlant" =>"",
			"SysName" => "驰骋工作流引擎ccbpm6",
			"SysNo" => "CCFlow"
			);
		return $array;
	}

	public function GetWebUserInfo(){
		$user=Session::get('user');
		if(empty($user['No'])){
		return "err@当前用户没有登录，请登录后再试。";
		}

		$array = array( //普通数组
			"EndJSON" => "0",
			"FK_Dept" =>$user['FK_Dept'],
			"IsAdmin" => "1",
			"Name" =>$user['Name'],
			"No" => $user['No'],
			"RootOfDept" =>"0",
			"RootOfFlow" => "F0",
			"RootOfForm" => "",
			"SID" => $user['SID']
			);
	
	   return $array;
	}
	//流程树
    public function GetFlowTreeTable(){
		$array=array();
		$data=Db::table('wf_flowsort')
		->field('No,Idx,Name,ParentNo')
		->fetchSql(false)
		->select();
		
		for($i=0;$i<count($data);$i++){
			$temporary['DTYPE']=-1;
			$temporary['IDX']=$data[$i]['Idx'];
			$temporary['ISPARENT']=1;
			$temporary['NAME']=$data[$i]['Name'];
			$temporary['NO']="F".$data[$i]['No'];
			$temporary['PARENTNO']="F".$data[$i]['ParentNo'];
			$temporary['TTYPE']="FLOWTYPE";
			array_push($array,$temporary);
		};
		$data=Db::table('wf_flow')
		->field('No,Idx,Name,FK_FlowSort')
		->order('Idx ASC')
		->fetchSql(false)
		->select();

		for($i=0;$i<count($data);$i++){
			$temporary['DTYPE']=0;
			$temporary['IDX']=$data[$i]['Idx'];
			$temporary['ISPARENT']=0;
			$temporary['NAME']=$data[$i]['No'].".".$data[$i]['Name'];
			$temporary['NO']=$data[$i]['No'];
			$temporary['PARENTNO']="F".$data[$i]['FK_FlowSort'];
			$temporary['TTYPE']="FLOW";
			array_push($array,$temporary);
		};
		return $array;
	}
	//表单树
    public function GetFormTreeTable(){
		$array=array();

		$data=Db::table('sys_formtree')
		->field('No,ParentNo,Name,Idx')
		->where('ParentNo',0)
		->fetchSql(false)
		->find();
		$temporary['Idx']=$data['Idx'];
		$temporary['IsParent']=1;
		$temporary['Name']=$data['Name'];
		$temporary['No']=$data['No'];
		$temporary['ParentNo']=$data['ParentNo'];
		$temporary['TType']="FORMTYPE";
		array_push($array,$temporary);

		$data=Db::table('sys_formtree')
		->field('No,ParentNo,Name,Idx')
		->order('Idx ASC')
		->fetchSql(false)
		->select();
		
		for($i=0;$i<count($data);$i++){
			$temporary['Idx']=$data[$i]['Idx'];
			$temporary['IsParent']=1;
			$temporary['Name']=$data[$i]['Name'];
			$temporary['No']=$data[$i]['No'];
			$temporary['ParentNo']=$data[$i]['ParentNo'];
			$temporary['TType']="FORMTYPE";
			array_push($array,$temporary);
		};
		$No=Db::table('sys_formtree')
		->field('No')
		->select();
		$where['AppType']=['=','0'];
		$where['FK_FormTree']=['in',$No];
		$data=Db::table('sys_mapdata')
		->field('No,FK_FormTree,Name,Idx')
		->where('FK_FormTree>0')
		->order('Idx ASC')
		->fetchSql(false)
		->select();
		for($i=0;$i<count($data);$i++){
			$temporary['Idx']=$data[$i]['Idx'];
			$temporary['IsParent']=0;
			$temporary['Name']=$data[$i]['Name'];
			$temporary['No']=$data[$i]['No'];
			$temporary['ParentNo']=$data[$i]['FK_FormTree'];
			$temporary['TType']="FORM";
			array_push($array,$temporary);
		};
		return $array;
	}
	//系统管理
	public function GetTreeJson_AdminMenu(){
		$array=array();
	
		$xmls =(array)simplexml_load_file('./DataUser/XML/AdminMenu.xml');
		$xml=$xmls;
		foreach($xml['Group'] as $value){
			$temporary['No']=(string)$value['No'];
			$temporary['Url']="";
			$temporary['Name']=(string)$value['Name'];
			$temporary['GroupNo']="0";
			$temporary['For']=null;
			array_push($array,$temporary);
		}
		foreach($xml['Item'] as $value){
			$temporary['No']=(string)$value['No'];
			$temporary['Url']=(string)$value['Url'];
			$temporary['Name']=(string)$value['Name'];
			$temporary['GroupNo']=(string)$value['GroupNo'];
			$temporary['For']=(string)$value['For'];
			array_push($array,$temporary);
		}
      
		return $array;

	}
	//流程实体初始化
	public function Entities_Init(){
		$EnsName=$this->request->post('EnsName');
		var_dump($EnsName);
	}

	
	public function TestFlow_GetRunOnPlant(){

	}
	//运行测试获取用户列表
	public function TestFlow_Init(){
		$data=Db::table('port_emp')
		->alias('a')
		->join('port_dept p','a.FK_Dept = p.No')
		->field('a.No,a.Name,p.Name as FK_DeptText')
		->select();

		return $data;
	}
	//查询节点属性以及左侧功能列表
	public function Entity_Init(){

		$PKVal=$this->request->post('PKVal');
		//查询节点详细信息
		$MainTable=Db::table('wf_node')
		->where('NodeID',$PKVal)
		->select();
		$array['MainTable']=$MainTable;
		//查询左侧功能列表
		$data=Db::table('leftlist')
		->select();

		//将查出来的Url中的变量换成当前接收到的 
		for($i=0;$i<count($data);$i++){

		if(strpos($data[$i]['Url'],"@FK_Node")!=false){
		  $data[$i]['Url']=str_replace("@FK_Node",$PKVal, $data[$i]['Url']);
		}
		if(strpos($data[$i]['Url'],"@FK_Flow")!=false){
		  $data[$i]['Url']=str_replace("@FK_Flow",$MainTable[0]['FK_Flow'], $data[$i]['Url']);
		}
		}

		$array['dtM']=$data;

		return $array;
	}
    //
	public function EntityOnly_Init(){
		$NodeID=$this->request->post('NodeID');
		$Lang=$this->request->post('Lang');
		$EnName=$this->request->post('EnName');
		//查询对应的节点
		$MainTable=Db::table('wf_node')
		->where('NodeID',$NodeID)
		->select();
		$array['MainTable']=$MainTable;

		//查询枚举
		$where['EnumKey']=['in','WhoExeIt,ReadReceipts,CondModel,CancelRole,RunModel,SubThreadType,SubFlowStartWay,ThreadKillRole,JumpWay,ReturnRole,ReturnOneNodeRole,CCRole,CCWriteTo,DelEnable,PrintPDFModle,PrintDocEnable,HuiQianRole'];
		$data=Db::table('sys_enum')
		->where($where)
		->select();
		$array['Sys_Enum']=$data;
		
		//获取分组标题
		$data=Db::table('sys_encfg')
		->field('GroupTitle')
		->where('No',$EnName)
		->find();
		$GroupTitle=array_filter(explode('@', $data['GroupTitle']));
		$Titles=array();
		foreach($GroupTitle as $value){
			$arr=explode('=', $value);
			$temporary['OID']=$arr[0];
			$temporary['Lab']=$arr[1];
			$temporary['Tip']="";
			$temporary['CtrlID']="";
			$temporary['CtrlType']="";
			if(count($arr)==3){
			$temporary['Lab']=$arr[2];
			}
		array_push($Titles,$temporary);
		}
		$array['Sys_GroupField']=$Titles;

		//获取节点属性名称
		$data=Db::table('sheet')
		->select();

		$array['Sys_MapAttr']=$data;

        //保存按钮
		$data=Db::table('workdata')
		->select();
		$array['Sys_MapData']=$data;

		$array['Sys_MapExt']=[];

		//查询左侧功能列表
		$data=Db::table('leftlist')
		->select();
	
		
		//将查出来的Url中的变量换成当前接收到的 
		for($i=0;$i<count($data);$i++){

		if(strpos($data[$i]['Url'],"@FK_Node")!=false){
			$data[$i]['Url']=str_replace("@FK_Node",$NodeID, $data[$i]['Url']);
		}
		if(strpos($data[$i]['Url'],"@FK_Flow")!=false){
		    $data[$i]['Url']=str_replace("@FK_Flow",$MainTable[0]['FK_Flow'], $data[$i]['Url']);
		}
		}
		$array['dtM']=$data;

		return $array;
	}
	//用户信息初始化
	public function WebUser_Init(){
		$user=Session::get('user');
		
		$dept=Db::table('port_dept')
		->field('No,Name')
		->where('No',$user['FK_Dept'])
		->find();

		$array = array( //普通数组
			"CustomerName" => "驰骋工作流",
			"CustomerNo" =>"CCFlow",
			"EndJSON" => "0",
			"FK_Dept" =>$dept['No'],
			"FK_DeptName" => "",
			"FK_DeptNameOfFull" =>"",
			"GroupNo" => "0",
			"Name" => $user['Name'],
			"No" =>  $user['No'],
			"SID" => ""
			);
		return $array;
	}
	//创建新的流程
	public function NewFlow(){
		$param = $this->request->param(); 
        //将接的字符串拆分成数组
		$paras=explode(",",$param['paras']);
	
		//查询当前最大的流程编号
		$data=Db::table('wf_flow')
		->field('max(No)')
		->find();

		$ndrptname="nd".($data['max(No)']+1)."rpt";
		$trackname="nd".($data['max(No)']+1)."track";
		//创建流程的rpt表
		$ndrpt="CREATE TABLE $ndrptname (
			`OID` int(11) NOT NULL COMMENT 'OID',
			`RDT` varchar(50) CHARACTER SET utf8 DEFAULT NULL COMMENT '更新时间',
			`Title` varchar(200) CHARACTER SET utf8 DEFAULT NULL COMMENT '标题',
			`FID` int(11) DEFAULT '0' COMMENT 'FID',
			`CDT` varchar(50) CHARACTER SET utf8 DEFAULT NULL COMMENT '发起时间',
			`Rec` varchar(32) CHARACTER SET utf8 DEFAULT NULL COMMENT '发起人',
			`Emps` text COMMENT 'Emps',
			`FK_Dept` varchar(100) CHARACTER SET utf8 DEFAULT NULL COMMENT '操作员部门',
			`FK_NY` varchar(7) CHARACTER SET utf8 DEFAULT NULL COMMENT '年月',
			`MyNum` int(11) DEFAULT '1' COMMENT '个数',
			`PNodeID` int(11) DEFAULT '0' COMMENT '父流程启动的节点',
			`GUID` varchar(32) CHARACTER SET utf8 DEFAULT '' COMMENT 'GUID',
			`PEmp` varchar(32) CHARACTER SET utf8 DEFAULT '' COMMENT '调起子流程的人员',
			`PrjNo` varchar(100) CHARACTER SET utf8 DEFAULT '' COMMENT '项目编号',
			`AtPara` text COMMENT '参数',
			`BillNo` varchar(100) CHARACTER SET utf8 DEFAULT '' COMMENT '单据编号',
			`PrjName` varchar(100) CHARACTER SET utf8 DEFAULT '' COMMENT '项目名称',
			`FlowNote` varchar(500) CHARACTER SET utf8 DEFAULT '' COMMENT '流程信息',
			`WFSta` int(11) DEFAULT '0' COMMENT '状态',
			`PWorkID` int(11) DEFAULT '0' COMMENT '父流程WorkID',
			`FlowDaySpan` float(11,2) DEFAULT '0.00' COMMENT '跨度(天)',
			`FlowEndNode` int(11) DEFAULT '0' COMMENT '结束节点',
			`FlowEnderRDT` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
			`FlowStartRDT` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
			`PFlowNo` varchar(3) CHARACTER SET utf8 DEFAULT '' COMMENT '父流程编号',
			`FlowEmps` varchar(1000) CHARACTER SET utf8 DEFAULT '' COMMENT '参与人',
			`WFState` int(11) DEFAULT '0' COMMENT '流程状态',
			`FlowEnder` varchar(32) CHARACTER SET utf8 DEFAULT '' COMMENT '结束人',
			`FlowStarter` varchar(32) CHARACTER SET utf8 DEFAULT '' COMMENT '发起人',
			PRIMARY KEY (`OID`)
		  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";
         //创建流程的track表
		  $track="CREATE TABLE $trackname (
			`MyPK` int(11) NOT NULL DEFAULT '0' COMMENT 'MyPK',
			`ActionType` int(11) DEFAULT '0' COMMENT '类型',
			`ActionTypeText` varchar(30) CHARACTER SET utf8 DEFAULT NULL COMMENT '类型(名称)',
			`FID` int(11) DEFAULT '0' COMMENT '流程ID',
			`WorkID` int(11) DEFAULT '0' COMMENT '工作ID',
			`NDFrom` int(11) DEFAULT '0' COMMENT '从节点',
			`NDFromT` varchar(300) CHARACTER SET utf8 DEFAULT NULL COMMENT '从节点(名称)',
			`NDTo` int(11) DEFAULT '0' COMMENT '到节点',
			`NDToT` varchar(999) CHARACTER SET utf8 DEFAULT NULL COMMENT '到节点(名称)',
			`EmpFrom` varchar(20) CHARACTER SET utf8 DEFAULT NULL COMMENT '从人员',
			`EmpFromT` varchar(30) CHARACTER SET utf8 DEFAULT NULL COMMENT '从人员(名称)',
			`EmpTo` varchar(2000) CHARACTER SET utf8 DEFAULT NULL COMMENT '到人员',
			`EmpToT` varchar(2000) CHARACTER SET utf8 DEFAULT NULL COMMENT '到人员(名称)',
			`RDT` varchar(20) CHARACTER SET utf8 DEFAULT NULL COMMENT '日期',
			`WorkTimeSpan` float DEFAULT NULL COMMENT '时间跨度(天)',
			`Msg` text COMMENT '消息',
			`NodeData` text COMMENT '节点数据(日志信息)',
			`Tag` varchar(300) CHARACTER SET utf8 DEFAULT NULL COMMENT '参数',
			`Exer` varchar(200) CHARACTER SET utf8 DEFAULT NULL COMMENT '执行人',
			PRIMARY KEY (`MyPK`)
		  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";
			$isTable = db()->query('SHOW TABLES LIKE '."'".$ndrptname."'");
			if( $isTable ){
				//echo '表存在';
			}else{
				//echo '表不存在';
				Db::execute($ndrpt);
			}
			$isTable =  db()->query('SHOW TABLES LIKE '."'".$trackname."'");
			if( $isTable ){
				//echo '表存在';
			}else{
				//echo '表不存在';
				Db::execute($track);
			}
		//向wf_flow表中添加一条数据
		Db::table('wf_flow')
		->data([
			'No'=>$data['max(No)']+1,
			'FK_FlowSort'=>$paras[0],
			'Name'=>$paras[1],
			'FlowMark'=>'',
			'FlowEventEntity'=>'',
			'TitleRole'=>'',
			'SysType'=>'',
			'HostRun'=>'',
			'BatchStartFields'=>'',
			'HistoryFields'=>'',
			'Paras'=>'@StartNodeX=200@StartNodeY=50@EndNodeX=200@EndNodeY=350'
			])
		->insert();

		//查询当前最新添加的流程
		$flow=Db::table('wf_flow')
		->where('No',$data['max(No)']+1)
		->find();

        $No=$flow['No'];//流程号
		$time=date("Y-m-d H:i",time());//获取当前时间
		$flowName=$flow['Name'];


		$firstNo=$No.'01';
		$secondNo=$No.'02';
		$HisToNDs='@'.$No.'02';
		$GroupStaNDs='@'.$No.'01@'.$No.'02';
        

		//向wf_node表中添加节点数据

$sql1="INSERT INTO `wf_node` 
VALUES
(
	'$firstNo',
	1,
	$No,
	'Start Node',
	'',
	0,
	0,
	2,
	0,
	0,
	1,
	1,
	'$time',
	'$time',
	0,
	'',
	0,
	0,
	0,
	'',
	0,
	0,
	100,
	0,
	'',
	0,
	0,
	0,
	0,
	'',
	0,
	0,
	0,
	0,
	'发送',
	'',
	'保存',
	1,
	'子线程',
	0,
	0,
	'跳转',
	0,
	'',
	'退回',
	0,
	'',
	1,
	'',
	'',
	'抄送',
	0,
	0,
	'移交',
	0,
	'删除',
	1,
	'结束流程',
	0,
	'打开公文',
	0,
	'打印Html',
	0,
	'打印pdf',
	0,
	'打包下载',
	0,
	'打印单据',
	0,
	'轨迹',
	1,
	'挂起',
	0,
	'查询',
	0,
	'审核',
	0,
	'加签',
	0,
	'会签',
	0,
	'流转自定义',
	0,
	'公文',
	0,
	'重要性',
	0,
	'分配',
	0,
	'关注',
	0,
	'确认',
	0,
	'列表',
	1,
	'批量审核',
	0,
	0,
	'',
	0,
	0,
	0,
	0,
	0,
	'',
	'',
	NULL,
	'审核信息',
	1,
	0,
	'',
	0,
	1,
	1,
	0,
	'审核',
	'同意',
	0,
	1,
	300.00,
	500.00,
	0.00,
	400.00,
	'',
	0,
	0,
	0,
	0,
	'前台',
	1,
	'$flowName',
	'',
	2.00,
	0,
	0,
	0,
	1.00,
	0,
	0,
	2.00,
	0,
	0,
	0,
	'',
	'',
	4,
	1,
	'',
	'',
	0,
	0,
	0,
	0,
	'',
	0,
	0,
	'',
	'',
	'',
	0,
	12,
	'',
	0,
	'http://',
	0,
	'',
	0,
	0,
	'',
	'',
	'$HisToNDs',
	'',
	'',
	'',
	'',
	'$GroupStaNDs',
	200,
	150,
	'',
	'',
	'',
	'轨迹',
	0,
	5.00,
	5.00,
	300.00,
	400.00,
	'子线程',
	0,
	5.00,
	5.00,
	300.00,
	400.00,
	'子流程',
	0,
	1,
	'启动子流程',
	'',
	5.00,
	5.00,
	300.00,
	400.00,
	'',
	0,
	0,
	'流转自定义',
	0,
	0,
	5.00,
	5.00,
	300.00,
	400.00,
	'打开本地',
	0,
	'打开模板',
	0,
	'保存',
	1,
	'接受修订',
	0,
	'拒绝修订',
	0,
	'套红按钮',
	0,
	1,
	0,
	'打印按钮',
	0,
	'签章按钮',
	0,
	'插入流程',
	0,
	0,
	0,
	'下载',
	0,
	1,
	NULL,
	1,
	0,
	NULL,
	0,
	5,
	'',
	'',
	1,
	0,
	0,
	0,
	'',
	'',
	'',
	'',
	'接受人',
	0,
	'节点时限',
	0,
	'打开本地',
	'打开模板',
	'保存',
	'接受修订',
	'拒绝修订',
	'套红',
	1,
	'打印',
	'签章',
	'插入流程',
	0,
	0,
	0,
	''
) ;

";

$sql2="INSERT INTO `wf_node` 
VALUES
  (
	'$secondNo',
	2,
	$No,
	'Node 2',
	'',
	0,
	0,
	2,
	0,
	0,
	1,
	1,
	'$time',
	'$time',
	0,
	'',
	0,
	0,
	0,
	'',
	0,
	0,
	100,
	0,
	'',
	0,
	0,
	0,
	0,
	'',
	0,
	0,
	0,
	0,
	'发送',
	'',
	'保存',
	1,
	'子线程',
	0,
	0,
	'跳转',
	0,
	'',
	'退回',
	1,
	'',
	1,
	'',
	'',
	'抄送',
	0,
	0,
	'移交',
	0,
	'删除',
	0,
	'结束流程',
	0,
	'打开公文',
	0,
	'打印Html',
	0,
	'打印pdf',
	0,
	'打包下载',
	0,
	'打印单据',
	0,
	'轨迹',
	1,
	'挂起',
	0,
	'查询',
	0,
	'审核',
	0,
	'加签',
	0,
	'会签',
	0,
	'流转自定义',
	0,
	'公文',
	0,
	'重要性',
	0,
	'分配',
	0,
	'关注',
	0,
	'确认',
	0,
	'列表',
	1,
	'批量审核',
	0,
	0,
	'',
	0,
	0,
	0,
	0,
	0,
	'',
	'',
	NULL,
	'审核信息',
	1,
	0,
	'',
	0,
	1,
	1,
	0,
	'审核',
	'同意',
	0,
	1,
	300.00,
	500.00,
	0.00,
	400.00,
	'',
	0,
	0,
	0,
	0,
	'审核',
	0,
	'$flowName',
	'',
	1.00,
	1,
	0,
	0,
	1.00,
	0,
	0,
	2.00,
	1,
	0,
	0,
	'',
	'',
	4,
	1,
	'',
	'',
	0,
	0,
	0,
	0,
	'',
	0,
	0,
	'',
	'',
	'',
	0,
	12,
	'',
	0,
	'http://',
	0,
	'',
	0,
	0,
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'$GroupStaNDs',
	200,
	250,
	'',
	'',
	'',
	'轨迹',
	0,
	5.00,
	5.00,
	300.00,
	400.00,
	'子线程',
	0,
	5.00,
	5.00,
	300.00,
	400.00,
	'子流程',
	0,
	1,
	'启动子流程',
	'',
	5.00,
	5.00,
	300.00,
	400.00,
	'',
	0,
	0,
	'流转自定义',
	0,
	0,
	5.00,
	5.00,
	300.00,
	400.00,
	'打开本地',
	0,
	'打开模板',
	0,
	'保存',
	1,
	'接受修订',
	0,
	'拒绝修订',
	0,
	'套红按钮',
	0,
	1,
	0,
	'打印按钮',
	0,
	'签章按钮',
	0,
	'插入流程',
	0,
	0,
	0,
	'下载',
	0,
	1,
	NULL,
	1,
	0,
	NULL,
	0,
	5,
	'',
	'',
	1,
	0,
	0,
	0,
	'',
	'',
	'',
	'',
	'接受人',
	0,
	'节点时限',
	0,
	'打开本地',
	'打开模板',
	'保存',
	'接受修订',
	'拒绝修订',
	'套红',
	1,
	'打印',
	'签章',
	'插入流程',
	0,
	0,
	0,
	''
  ) ;

";
	
	 Db::execute($sql1);
	 Db::execute($sql2);
	
	//向wf_direction表中添加一条数据记录
	Db::table('wf_direction')
    ->data([
		'MyPK'=>$No.'_'.$firstNo.'_'.$secondNo,
		'FK_Flow'=>$No,
		'Node'=>$firstNo,
		'ToNode'=>$secondNo,
		'IsCanBack'=>0,
		'Dots'=>'',
		])
	->insert();
	
	//向`sys_frmline`中添加
	// (
	// 	'ff4ade6b-6822-43cc-bb70-3f4aaa9aea29',
	// 	'ND21101',
	// 	83.36,
	// 	120.91,
	// 	717.91,
	// 	120.91,
	// 	9,
	// 	9,
	// 	2,
	// 	'Black',
	// 	''
	//   ),
	// Db::table('sys_frmline')
    // ->data([
	// 	'MyPK'=>$No.'_'.$firstNo.'_'.$secondNo,
	// 	'FK_MapData'=>$No,
	// 	'X1'=>$firstNo,
	// 	'Y1'=>$secondNo,
	// 	'X2'=>0,
	// 	'Y2'=>'',
	// 	'X'=>'',
	// 	'Y'=>'',
	// 	'BorderWidth'=>'',
	// 	'BorderColor'=>'',
	// 	'GUID'=>''
	// 	])
	// ->insert();

	//向`sys_groupfield`表中添加

	$num=Db::table('sys_groupfield')
	->field('max(OID)')
	->find();

	$datas = [
		[
			'OID' => $num['max(OID)']+2, 
			'Lab' => 'Start Node', 
			'FrmID' => 'ND'.$firstNo, 
			'CtrlType' => '', 
			'CtrlID' => '', 
			'Idx' => 1, 
			'GUID' => '', 
			'AtPara' => ''
		],
		[
			'OID' => $num['max(OID)']+4, 
			'Lab' => 'Node 2', 
			'FrmID' => 'ND'.$secondNo, 
			'CtrlType' => '', 
			'CtrlID' => '', 
			'Idx' => 1, 
			'GUID' => '', 
			'AtPara' => ''
		],
		[
			'OID' => $num['max(OID)']+6, 
			'Lab' => '审核组件', 
			'FrmID' => $firstNo, 
			'CtrlType' => 'Ath', 
			'CtrlID' => $firstNo.'_FrmWorkCheck', 
			'Idx' => 1, 
			'GUID' => '', 
			'AtPara' => ''
		],
		[
			'OID' => $num['max(OID)']+8, 
			'Lab' => '审核组件', 
			'FrmID' => $secondNo, 
			'CtrlType' => 'Ath', 
			'CtrlID' => $secondNo.'_FrmWorkCheck', 
			'Idx' => 1, 
			'GUID' => '', 
			'AtPara' => ''
		],
		[
			'OID' => $num['max(OID)']+10, 
			'Lab' => '基础信息', 
			'FrmID' => 'ND'.$firstNo.'Rpt', 
			'CtrlType' => '', 
			'CtrlID' => '', 
			'Idx' => 1, 
			'GUID' => '', 
			'AtPara' => ''
		],
		[
			'OID' => $num['max(OID)']+12, 
			'Lab' => '流程信息', 
			'FrmID' =>'ND'.$secondNo.'Rpt', 
			'CtrlType' => '', 
			'CtrlID' => '', 
			'Idx' => 2, 
			'GUID' => '', 
			'AtPara' => ''
		],
	];
	Db::name('sys_groupfield')->insertAll($datas);


	//向sys_mapdata中添加数据
	$datas = [
		[
			'No' => 'ND'.$firstNo, 
			'Name' => 'Start Node'
		],
		[
			'No' => 'ND'.$secondNo, 
			'Name' => 'Node 2'
		],
		[
			'No' => 'ND'.$No.'Rpt', 
			'Name' => $flowName
		]
	];
	Db::name('sys_mapdata')->insertAll($datas);

		return (int)$No;
	}

	//跳转到接口页面
	public function TestFlow_ReturnToUser(){
		$DoWhat=$this->request->post('DoWhat');
		$UserNo=$this->request->post('UserNo');
		$FK_Flow=$this->request->post('FK_Flow');

		$data=Db::table('port_emp')
		->field('SID')
		->where('No',$UserNo)
		->find();
		$url = "../../WF/Port.htm?UserNo=".$UserNo."&SID=".$data['SID']."&DoWhat=".$DoWhat."&FK_Flow=".$FK_Flow."&IsMobile=";
		
		return  "url@".$url;
	}
	//页面接口
	public function Port_Init(){
		$DoWhat=$this->request->post('DoWhat');
		$UserNo=$this->request->post('UserNo');
		$FK_Flow=$this->request->post('FK_Flow');
		$SID=$this->request->post('SID');
		if($DoWhat==null||$UserNo==null||$FK_Flow==null||$SID==null){
			return "err@必要的参数没有传入，请参考接口规则。";
		}
		$user=Session::get('user');
	
		if($user['No']!=$UserNo){
			return "err@非法的访问，请与管理员联系。SID=".$SID;
		}
		 //发起流程.
		if ($DoWhat==("StartClassic")){
			if ($FK_Flow == null)
			{
				return "url@./AppClassic/Home.htm";
			}
			else
			{
				return "url@./AppClassic/Home.htm?FK_Flow=$FK_Flow&FK_Node=".$FK_Flow."01";
			}
		}
	}
	public function Home_Init(){
	
		$user=Session::get('user');
		$dept=Db::table('port_dept')
		->field('Name')
		->where('No',$user['FK_Dept'])
		->find();

		$array=array(
			"Todolist_Runing"=> "0",
			"Todolist_Sharing"=> "0",
			"UserNo"=> 	$user['No'],
			"Todolist_Apply"=> "0",
			"CustomerName"=> "驰骋工作流",
			"Todolist_Complete"=> "1",
			"Todolist_MyStartFlow"=> "3",
			"Todolist_EmpWorks"=> "2",
			"Todolist_CCWorks"=> "0",
			"SysName"=> "驰骋工作流引擎ccbpm6",
			"Todolist_MyFlow"=> "1",
			"Todolist_Draft"=> "0",
			"UserDeptName"=> $dept['Name'],
			"UserName"=> $user['Name'],
			"EndJSON"=> "0"
		);
		return $array;
	}
	public function Start_Init(){
		$array=array();
		$data=Db::table('wf_flowsort')
		->field('No,Idx,Name,ParentNo')
		->fetchSql(false)
		->select();
		
		for($i=0;$i<count($data);$i++){
			$temporary['Domain']="";
			$temporary['Idx']=$data[$i]['Idx'];
			$temporary['Name']=$data[$i]['Name'];
			$temporary['No']=$data[$i]['No'];
			$temporary['OrgNo']="0";
			$temporary['ParentNo']=$data[$i]['ParentNo'];
			array_push($array,$temporary);
		};
		
		$data=Db::table('wf_flow')

		->fetchSql(false)
		->select();

		$result['Sort']=$array;
		$result['Start']=$data;

		return $result;
	}
	//流程初始化
	public function MyFlow_Init(){
		$param = $this->request->param(); 

		//如果是从发送处进来
		if(empty($param['WorkID'])&&empty($param['FK_Node'])){
		
        return $this->SendInit($param['FK_Flow']);
		}
		
		$where['WorkID']=['=',$param['WorkID']];
		
		$data=Db::table('wf_generworkflow')
		->where($where)
		->find();

		$user=Session::get('user');

		$Flow=Db::table('wf_flow')
		->where('No',$param['FK_Flow'])
		->find();
        
		$url="MyFlowGener.htm?WorkID=".$data['WorkID']."&NodeID=".$param['FK_Node']."&FK_Node=".$data['FK_Node']."&FID=".$data['FID']."&UserNo=".$user['No']."&SID=".$user['SID']."&FK_Flow=".$param['FK_Flow'];
		
		return "url@".$url;
	}

	//发起流程初始化
	public function SendInit($FK_Flow){
		$where['WFState']=['=',0];
		$where['FK_Flow']=['=',$FK_Flow];
		
		$data=Db::table('wf_generworkflow')
		->field("max(WorkID),FID")
		->where($where)
		->find();

		$user=Session::get('user');

		$Flow=Db::table('wf_flow')
		->where('No',$FK_Flow)
		->find();
        //查询流程第一步的节点
		$Node=Db::table('wf_node')
		->where('FK_Flow',$FK_Flow)
		->where('Step',1)
		->find();

		//如果为空则生成一个新的流程
		if(empty($data['max(WorkID)'])){

		
        //查询人员对应的部门信息
		$dept=Db::table('port_dept')
		->where('No',$user['FK_Dept'])
		->find();
        
		$WorkID=Db::table('wf_generworkflow')
		->field('max(WorkID)')
		->find();
    
		Db::table('wf_generworkflow')
		->data([
			'WorkID'=>$WorkID['max(WorkID)']+1,
			'FID'=>0,
			'FK_FlowSort'=>99,
			'SysType'=>'',
			'FK_Flow'=>$Flow['No'],
			'FlowName'=>$Flow['Name'],
			'Title'=>$dept['Name']."-".$user['No'].",".$user['Name']."在".date("Y-m-d h:i",time())."发起",
			'WFSta'=>0,
			'WFState'=>0,
			'Starter'=>$user['No'],
			'StarterName'=>$user['Name'],
			'Sender'=>$user['No'],
			'RDT'=>date("Y-m-d h:i",time()),
			'SendDT'=>date("Y-m-d h:i",time()),
			'FK_Node'=>$Node['NodeID'],
			'NodeName'=>$Node['Name'],
			'FK_Dept'=>$dept['No'],
			'DeptName'=>$dept['Name'],
			'PRI'=>1,
			'SDTOfNode'=>date("Y-m-d h:i",time()),
			'SDTOfFlow'=>date("Y-m-d h:i",time()),
			'PFlowNo'=>'',
			'PWorkID'=>0,
			'PNodeID'=>0,
			'PFID'=>0,
			'PEmp'=>'',
			'GuestNo'=>'',
			'GuestName'=>'',
			'BillNo'=>'',
			'FlowNote'=>'',
			'TodoEmps'=>'admin',
			'TodoEmpsNum'=>1,
			'TaskSta'=>0,
			'AtPara'=>'',
			'Emps'=>'Emps@admin,admin',
			'GUID'=>'',
			'FK_NY'=>date("Y-m",time()),
			'WeekNum'=>0,
			'TSpan'=>0,
			'TodoSta'=>0,
			'MyNum'=>1,
			'Domain'=>''
			])
		->insert();

		$data=Db::table('wf_generworkflow')
		->field("max(WorkID),FID")
		->where($where)
		->find();
		}

		$url="MyFlowGener.htm?WorkID=".$data['max(WorkID)']."&NodeID=".$FK_Flow."01"."&FK_Node=".$FK_Flow."01"."&FID=".$data['FID']."&UserNo=".$user['No']."&SID=".$user['SID']."&FK_Flow=".$FK_Flow;
		
		return "url@".$url;

	}



	//返回四个按钮的html以及跳转路径
	public function InitToolBar(){
		$param = $this->request->param(); 

		$result=Db::table('nd'.$param['FK_Flow'].'rpt')
		->where('OID',$param['WorkID'])
		->find();

		//如果nd。。。rpt表中吗没有数据，则创建一条数据
		if(empty($result['OID'])){

			$user=Session::get('user');
	
			
			//查询流程最后一步的节点
			$Step=Db::table('wf_node')
			->field('max(Step)')
			->where('FK_Flow',$param['FK_Flow'])
			->find();
	
			$Node=Db::table('wf_node')
			->where('FK_Flow',$param['FK_Flow'])
			->where('Step',$Step['max(Step)'])
			->find();
			
	
			//查询人员对应的部门信息
			$dept=Db::table('port_dept')
			->where('No',$user['FK_Dept'])
			->find();
	
			Db::table('nd'.$param['FK_Flow'].'rpt')
			->data([
				'OID'=>$param['WorkID'],
				'RDT'=>date("Y-m-d h:i",time()),
				'Title'=>$dept['Name']."-".$user['No'].",".$user['Name']."在".date("Y-m-d h:i",time())."发起",
				'FID'=>0,
				'CDT'=>date("Y-m-d h:i",time()),
				'Rec'=>$user['No'],
				'Emps'=>$user['No'],
				'FK_Dept'=>$dept['No'],
				'FK_NY'=>date("Y-m",time()),
				'MyNum'=>1,
				'PNodeID'=>0,
				'GUID'=>'',
				'PEmp'=>'',
				'PrjNo'=>'',
				'AtPara'=>'',
				'BillNo'=>'',
				'PrjName'=>'',
				'FlowNote'=>'',
				'WFSta'=>0,
				'PWorkID'=>'',
				'FlowDaySpan'=>'0.00',
				'FlowEndNode'=>$Node['NodeID'],
				'FlowEnderRDT'=>date("Y-m-d h:i",time()),
				'FlowStartRDT'=>date("Y-m-d h:i",time()),
				'PFlowNo'=>'',
				'FlowEmps'=>'FlowEmps@'.$user['No'].','.$user['Name'],
				'WFState'=>0,
				'FlowEnder'=>$user['No'],
				'FlowStarter'=>$user['No']
				])
			->insert();
		}

		$WorkID=$this->request->post('WorkID');
		$NodeID=$this->request->post('NodeID');
		$FK_Node=$this->request->post('FK_Node');
		$FID=$this->request->post('FID');
		$UserNo=$this->request->post('UserNo');
		$SID=$this->request->post('SID');
		$FK_Flow=$this->request->post('FK_Flow');
        $time=date('M-d H:i',time()); 
		$send="<input name='Send' type=button  value='发送' enable=true onclick=\"  if(SysCheckFrm()==false) return false;Send();\" />";
		$save="<input name='Save' type=button  value='保存' enable=true onclick=\"   if(SysCheckFrm()==false) return false;Save();\" />";
		$delete="<input name='Delete' type=button  value='删除' enable=true onclick=\"To('/WF/MyFlowInfo.htm?DoType=DeleteFlow&FK_Node=$FK_Node&FID=$FID&WorkID=$WorkID&FK_Flow=$FK_Flow&s=$time); \" />";
		$back="<input name='Return' type=button  value='退回' enable=true onclick=\"ReturnWork('./WorkOpt/ReturnWork.htm?FK_Node=$FK_Node&FID=$FID&WorkID=$WorkID&FK_Flow=$FK_Flow&s=$time',''); \" />";
		$track="<input type=button name='Track'  value='轨迹' enable=true onclick=\"WinOpen('/WF/WorkOpt/OneWork/OneWork.htm?CurrTab=Truck&WorkID=$WorkID&FK_Flow=$FK_Flow&FID=$FID&FK_Node=$FK_Node&s=$time','ds'); \" />";

		$workflow=Db::table('wf_generworkflow')
		->where('WorkID',$param['WorkID'])
		->find();
        if($workflow['WFState']==0){

	     	return $send.$save.$delete.$track;
		}else{

			return $send.$save.$back.$track;
		}
	}
	//
	public function GenerWorkNode(){
		$param = $this->request->param(); 
		$result['AlertMsg']=[];
		//获取所有部门的数据集
		$result['BP.Port.Depts']=Db::table('port_dept')
		->field('Name,No,ParentNo')
		->select();
		//查询对应的流程详情
		$data=Db::table('wf_generworkflow')
		->where('WorkID',$param['WorkID'])
		->find();
		$result['MainTable']=Db::table("nd".$param['FK_Flow']."rpt")
		->where('OID',$param['WorkID'])
		->select();
		
		$result['Sys_Enum']=[];
		$result['Sys_FrmAttachment']=[];
		$result['Sys_FrmBtn']=[];
		$result['Sys_FrmEle']=[];

	    $result['Sys_FrmImg']=Db::table('sys_frmimg')
		->where('FK_MapData',"ND".$param['NodeID'])
		->select();
		
		$result['Sys_FrmImgAth']=[];
		$result['Sys_FrmImgAthDB']=[];

		$result['Sys_FrmLab']=Db::table('sys_frmlab')
		->where('FK_MapData',"ND".$param['NodeID'])
		->select();

		$result['Sys_FrmLine']=Db::table('sys_frmline')
		->where('FK_MapData',"ND".$param['NodeID'])
		->select();

		$result['Sys_FrmLink']=[];
		$result['Sys_FrmRB']=[];

		$result['Sys_GroupField']=Db::table('sys_groupfield')
		->where('FrmID',"ND".$param['NodeID'])
		->select();

		$result['Sys_MapAttr']=Db::table('sys_mapattr')
		->where('FK_MapData',"ND".$param['NodeID'])
		->select();

		$result['Sys_MapData']=Db::table('sys_mapdata')
		->where('No',"ND".$param['NodeID'])
		->select();

		$result['Sys_MapDtl']=[];
		$result['Sys_MapExt']=[];
		$result['Sys_MapFrame']=[];

		$data=Db::table('wf_node')
		->where('NodeID',$param['NodeID'])
		->select();

		$result['ToNodes'][0]=array(
			"IsSelectEmps"=> "1",
			"IsSelected"=> "0",
			"Name"=> "审批",
			"No"=> str_replace("@","",$data[0]['HisToNDs'])
		);

	

		$result['WF_FrmNodeComponent']=[];


		$result['WF_GenerWorkFlow']=Db::table('wf_generworkflow')
		->where('WorkID',$param['WorkID'])
		->select();
		$result['WF_Node']=$data;

        return $result;
	}
	//保存流程
	public function Save(){
		$param = $this->request->param(); 

		
		//获取参数的key值
	    $keys=array_keys($param );
		$array=array();
		foreach($keys as $value){
	
	      if(strpos($value,'TB_')!==false){

			$field=str_replace("TB_","",$value);

			Db::table("nd".$param['FK_Flow']."rpt")
			->update([
			 $field => $param["$value"],
			 'OID'=>$param['WorkID']
			]);
		  }
          
		}
	
		return "保存成功";
	}
	//
	public function Accepter_Init(){
		$param = $this->request->param(); 

		//如果已经是最后一个节点，则直接完成
		$Step=Db::table('wf_direction')
		->field('max(Node)')
		->where('FK_Flow',$param['FK_Flow'])
		->find();

		$Node=Db::table('wf_direction')
		->where('Node',$Step['max(Node)'])
		->find();

		$NowNode=Db::table('wf_direction')
		->where('Node',$param['FK_Node'])
		->find();

        if($Node['ToNode']==$param['FK_Node']){
		$url="AccepterOfGener.htm?WorkID=".$param['WorkID']."&FK_Node=".$param['FK_Node']."&FK_Flow=".$param['FK_Flow']."&ToNode=";
		}else{
		$url="AccepterOfGener.htm?WorkID=".$param['WorkID']."&FK_Node=".$param['FK_Node']."&FK_Flow=".$param['FK_Flow']."&ToNode=".$NowNode['ToNode'];
		}
		return "url@".$url;
	}
	public function AccepterOfGener_Init(){
		$param = $this->request->param();
	
		$where['WorkID']=['=',$param['WorkID']];
		$data=Db::table('wf_selectaccper')
		->where($where)
		->select();

		return $data;
	}
	//接收人初始化
	public function SelectEmps_Init(){
		$param = $this->request->param();
		$where['No|ParentNo']=['=',$param['FK_Dept']];
		//可以接收的部门
		$result['Depts']=Db::table('port_dept')
		->field('No,Name,ParentNo')
		->where($where)
		->order('Idx')
		->select();
		//可以接收的人员
		$result['Emps']=Db::table('port_emp')
		->field('No,Name,FK_Dept,Idx')
		->where('FK_Dept',$param['FK_Dept'])
		->order('Idx')
		->select();

		return $result;
	}
	//根据用户输入的名称进行模糊查询
	public function AccepterOfGener_SelectEmps(){
		$param = $this->request->param();
	
		$where['No|Name|PinYin']=['like',"%".$param['TB_Emps']."%"];
		
		$data=Db::table('port_emp')
		->field('No,Name,FK_Dept')
		->where($where)
		->select();

		$array=array();
		
		foreach($data as $value){
        $result=Db::table('port_dept')
		->where('No',$value['FK_Dept'])
		->find();

		$temporary['Name']=$value['Name']."/".$result['Name'];
		$temporary['No']=$value['No'];

		array_push($array,$temporary);
		}

		return $array;
	}
    //添加数据到wf_selectaccper
	public function AccepterOfGener_AddEmps(){
	    $param = $this->request->param();
	
        $data=Db::table('wf_selectaccper')
		->where('FK_Emp',$param['AddEmps'])
		->where('WorkID',$param['WorkID'])
		->find();
	
		if(!empty($data)){
			return "err@人员名称重复,导致部分人员插入失败.";
		}
        //查询emp
		$emp=Db::table('port_emp')
		->alias('p')
		->join('port_dept w','p.FK_Dept = w.No')
		->field('p.No,p.Name,w.Name as FK_Dept')
		->where('p.No',$param['AddEmps'])
		->find();
        //添加一条新纪录到wf_selectaccper表
		Db::table('wf_selectaccper')
		->data([
			'MyPK'=>$param['ToNode']."_".$param['WorkID']."_".$emp['No'],
			'FK_Node'=>$param['ToNode'],
			'WorkID'=>$param['WorkID'],
			'FK_Emp'=>$emp['No'],
			'EmpName'=>$emp['Name'],
			'DeptName'=>$emp['FK_Dept'],
			'AccType'=>0,
			'Rec'=>"admin",
			'Info'=>'',
			'IsRemember'=>0,
			'Idx'=>0,
			'Tag'=>'',
			'TimeLimit'=>0,
			'TSpanHour'=>0,
			'ADT'=>'',
			'SDT'=>''
			])
		->insert();

		$where['WorkID']=['=',$param['WorkID']];
		$data=Db::table('wf_selectaccper')
		->where($where)
		->select();

		return $data;
	}
	//删除wf_selectaccper中的数据
	public function AccepterOfGener_Delete(){
		$param = $this->request->param();

		$where['WorkID']=$param['WorkID'];
		$where['FK_Emp']=$param['FK_Emp'];

		Db::table('wf_selectaccper')
		->where($where)
		->delete();

		$data=Db::table('wf_selectaccper')
		->where('WorkID',$param['WorkID'])
		->select();

		return $data;

	}
	//执行发送
	public function AccepterOfGener_Send(){
		$param = $this->request->param();

		//如果已经是最后一个节点，则直接完成
		$Step=Db::table('wf_direction')
		->field('max(Node)')
		->where('FK_Flow',$param['FK_Flow'])
		->find();

		$Node=Db::table('wf_direction')
		->where('Node',$Step['max(Node)'])
		->find();
	

        if($Node['ToNode']==$param['FK_Node']){

			$this->LastNode($param);
			return "@流程已经走到最后一个节点，流程成功结束。@流程已经结束@";
		}

	
		$sessionuser=Session::get('user');

		//当前节点
		$CurrentNode=Db::table('wf_node')
		->where('NodeID',$param['FK_Node'])
		->find();
		
		//接收的节点
		$NextNode=Db::table('wf_node')
		->field('Name')
		->where('NodeID',$param['ToNode'])
		->find();
		//查询处理人

		$user;
		//如果没有添加接收人就走默认的接收人
		if(!empty($param['AddEmps'])){

		$user=Db::table('port_emp')
		->field('No,Name,SID,FK_Dept')
		->where('No',$param['AddEmps'])
		->find();

		}
		else{
	
		$data=Db::table('wf_selectaccper')
		->where('WorkID',$param['WorkID'])
		->find();

		$user=Db::table('port_emp')
		->field('No,Name,SID,FK_Dept')
		->where('No',$data['FK_Emp'])
		->find();

		}
	
		//查询人员对应的部门信息
		$dept=Db::table('port_dept')
		->where('No',$user['FK_Dept'])
		->find();

		//更新nd???rpt表
		Db::table('nd'.$param['FK_Flow'].'rpt')
		->update([
		'FlowEmps' => "FlowEmps"."@".$sessionuser['No'].",".$sessionuser['Name'],
		'WFState'  =>2,
		'FlowEnderRDT' => date("y-m-d H:i",time()),
		'FlowStartRDT' => date("y-m-d H:i",time()),
		'FlowEndNode' => $param['ToNode'],
		'OID'=>$param['WorkID']
		]);

		//nd???track表中新加一条数据



		//wf_generworkerlist中新增两条数据
		$where=[];
		$where['WorkID']=['=',$param['WorkID']];
		$where['FK_Emp']=['=',$sessionuser['No']];
		$where['FK_Node']=['=',$param['FK_Node']];
	
		$zhujian=Db::table('wf_generworkerlist')
		->where($where)
		->find();
		if(empty($zhujian)){
		Db::table('wf_generworkerlist')
		->data([
			'WorkID'=>$param['WorkID'],
			'FK_Emp'=>$sessionuser['No'],
			'FK_Node'=>$param['FK_Node'],
			'FID'=>0,
			'FK_EmpText'=>$sessionuser['No'],
			'FK_NodeText'=>$CurrentNode['Name'],
			'FK_Flow'=>$param['FK_Flow'],
			'FK_Dept'=>$dept['No'],
			'SDT'=>'无',
			'DTOfWarning'=>date("Y-m-D h:i",time()),
			'RDT'=>date("Y-m-D h:i",time()),
			'CDT'=>date("Y-m-D h:i",time()),
			'IsEnable'=>1,
			'IsRead'=>0,
			'IsPass'=>1,
			'WhoExeIt'=>0,
			'Sender'=>'',
			'PRI'=>1,
			'PressTimes'=>0,
			'DTOfHungUp'=>'',
			'DTOfUnHungUp'=>'',
			'HungUpTimes'=>0,
			'GuestNo'=>'',
			'GuestName'=>'',
			'AtPara'=>''
			])
		->insert();
		}

		$where=[];
		$where['WorkID']=['=',$param['WorkID']];
		$where['FK_Emp']=['=',$sessionuser['No']];
		$where['FK_Node']=['=',$param['ToNode']];
	
		$zhujian=Db::table('wf_generworkerlist')
		->where($where)
		->find();
		if(empty($zhujian)){
		Db::table('wf_generworkerlist')
		->data([
			'WorkID'=>$param['WorkID'],
			'FK_Emp'=>$sessionuser['No'],
			'FK_Node'=>$param['ToNode'],
			'FID'=>0,
			'FK_EmpText'=>$sessionuser['No'],
			'FK_NodeText'=>$NextNode['Name'],
			'FK_Flow'=>$param['FK_Flow'],
			'FK_Dept'=>$dept['No'],
			'SDT'=>date("Y-m-d H:i",strtotime("+1days",time())),
			'DTOfWarning'=>date("Y-m-d H:i",strtotime("+1days",time())),
			'RDT'=>date("Y-m-D h:i",time()),
			'CDT'=>date("Y-m-D h:i",time()),
			'IsEnable'=>1,
			'IsRead'=>0,
			'IsPass'=>0,
			'WhoExeIt'=>0,
			'Sender'=>$sessionuser['No'].",".$sessionuser['Name'],
			'PRI'=>1,
			'PressTimes'=>0,
			'DTOfHungUp'=>'',
			'DTOfUnHungUp'=>'',
			'HungUpTimes'=>0,
			'GuestNo'=>'',
			'GuestName'=>'',
			'AtPara'=>'@FK_DeptT='.$dept['Name']
			])
		->insert();
		}
	
		//修改wf_generworkflow表
		Db::table('wf_generworkflow')
		->update([
			'WFState' => 2,//0是起始默认值 ，，在途是2  已完成是3
			'Sender' =>$sessionuser['No'],
			'RDT' => date("y-m-d H:i:s",time()),
			'SendDT' => date("y-m-d H:i:s",time()),
			'FK_Node' =>  $param['ToNode'],
			'NodeName' =>  $NextNode['Name'],
			'SDTOfNode' => date("Y-m-d H:i",strtotime("+1days",time())),
			'TodoEmps' =>  $user['No'],
			'TodoEmpsNum' => 1,
			'AtPara' =>  '',
			'Emps' =>  "Emps"."@".$sessionuser['No'].",".$sessionuser['Name'],
			'WorkID'=>$param['WorkID']
		]);

		//wf_selectaccper中添加一条记录


		$zhujian=Db::table('wf_selectaccper')
		->where('MyPK',$param['ToNode']."_".$param['WorkID']."_".$user['No'])
		->find();
		if(empty($zhujian)){
		Db::table('wf_selectaccper')
		->data([
			'MyPK'=>$param['ToNode']."_".$param['WorkID']."_".$user['No'],
			'FK_Node'=>$param['ToNode'],
			'WorkID'=>$param['WorkID'],
			'FK_Emp'=>$user['No'],
			'EmpName'=>$user['Name'],
			'DeptName'=>$dept['Name'],
			'AccType'=>0,
			'Rec'=>"admin",
			'Info'=>'',
			'IsRemember'=>0,
			'Idx'=>0,
			'Tag'=>'',
			'TimeLimit'=>0,
			'TSpanHour'=>0,
			'ADT'=>'',
			'SDT'=>''
			])
		->insert();
		}

		$FK_Flow=$param['FK_Flow'];
		$result1="<br>@当前工作[".$CurrentNode['Name']."]已经完成.<br>@发送给如下1位处理人(".$user['No'].",".$user['Name'].").<br>";
		$result2="@<a href='./WorkOpt/UnSend.htm?DoType=UnSend&UserNo=".$user['No']."&SID=".$user['SID']."&WorkID=".$param['WorkID']."&FK_Flow=$FK_Flow'><img src='./Img/Action/UnSend.png' border=0/>撤销本次发送</a><br>";
		$result3="@下一步工作[".$NextNode['Name']."]成功启动.<br>@已向:{".$user['No']."}发送提醒信息.";
		
		return $result1.$result2.$result3;

	}

	//流程已经走到最后一个节点时
	public function LastNode($param){

		$sessionuser=Session::get('user');
        //修改rpt表中的数据状态
		Db::table('nd'.$param['FK_Flow'].'rpt')
		->update([
		'WFState'  =>3,
		'WFSta'  =>1,
		'FlowEmps' => 'FlowEmps'.$sessionuser['No'],
		'OID'=>$param['WorkID']
		]);
		//strack表中添加一条数据

		//删除`wf_generworkerlist`表中对应的数据
		Db::table('wf_generworkerlist')
		->where('WorkID',$param['WorkID'])
		->delete();

		//修改wf_generworkflow表中数据得状态
		Db::table('wf_generworkflow')
		->update([
		'WFState'  =>3,
		'WFSta'  =>1,
		'SendDT' =>date('Y-m-d H:i',time()),
		'TodoEmps'  =>'TodoEmps'.$sessionuser['No'],
		// 'AtPara'  =>1,
		'WorkID'=>$param['WorkID']
		]);
		 
	}

	//删除流程
	public function DeleteFlow(){
		$param = $this->request->param();

		//删除rpt中的数据
		Db::table('nd'.$param['FK_Flow'].'rpt')
		->where('OID',$param['WorkID'])
		->delete();

		// 删除track中的数据
		Db::table('nd'.$param['FK_Flow'].'track')
		->where('WorkID',$param['WorkID'])
		->delete();

		// sys_serial中修改数据
		Db::table('sys_serial')
		->update([
			'IntVal' => $param['WorkID'],
			'CfgKey'=>'WorkID'
		]);

		// `wf_generworkerlist`删除数据
		Db::table('wf_generworkerlist')
		->where('WorkID',$param['WorkID'])
		->delete();

		// `wf_generworkflow`删除数据
		Db::table('wf_generworkflow')
		->where('WorkID',$param['WorkID'])
		->delete();

		return "删除成功";

	}


	//代办，流程状态是2的
	public function Todolist_Init(){
		$user=Session::get('user');

        $where['WFState']=['=',2];
		$where['TodoEmps']=['like',"%".$user['No']."%"];

		$data=Db::table('wf_generworkflow')
		->where($where)
		->order('WorkID desc')
		->select();

        return $data;
	}

	//在途流程状态是2但是有接收人就说明还没走完
	public function Runing_Init(){
		$data=Db::table('wf_generworkflow')
		->where('WFState',2)
		->where('TodoEmpsNum>0')
		->select();

        return $data;
	}

	//已完成
	public function Complete_Init(){
		$user=Session::get('user');

		$where['WFState']=['=',3];
		$where['Emps']=['like',"%".$user['No']."%"];

		$data=Db::table('wf_generworkflow')
		->where($where)
		->select();

        return $data;
	}
	//创建节点
	public function CreateNode(){
	  $param=$this->request->param();
      //查询出当前流程最大的节点
	  $MaxNode=Db::table('wf_node')
	  ->field('max(NodeID)')
	  ->where('FK_Flow',$param['FK_Flow'])
	  ->find();
	
	  $firstNo=$MaxNode['max(NodeID)']+1;
  
	  $data=Db::table('wf_node')
	  ->field('Step,FlowName')
      ->where('NodeID', $MaxNode['max(NodeID)'])
	  ->find();
  
	  $Step=((int)$data['Step']+1);
	  $No=$param['FK_Flow'];
	  $Name='New Node '.$Step;
	  $time=date('Y-m-d H:i',time());
	  $flowName=$data['FlowName'];
	  $x=$param['X'];
	  $y=$param['Y'];
	  //向wf_node中添加一条新的数据
$sql="INSERT INTO `wf_node` 
VALUES
(
	'$firstNo',
	$Step,
	$No,
	'$Name',
	'',
	0,
	0,
	2,
	0,
	0,
	1,
	1,
	'$time',
	'$time',
	0,
	'',
	0,
	0,
	0,
	'',
	0,
	0,
	100,
	0,
	'',
	0,
	0,
	0,
	0,
	'',
	0,
	0,
	0,
	0,
	'发送',
	'',
	'保存',
	1,
	'子线程',
	0,
	0,
	'跳转',
	0,
	'',
	'退回',
	0,
	'',
	1,
	'',
	'',
	'抄送',
	0,
	0,
	'移交',
	0,
	'删除',
	1,
	'结束流程',
	0,
	'打开公文',
	0,
	'打印Html',
	0,
	'打印pdf',
	0,
	'打包下载',
	0,
	'打印单据',
	0,
	'轨迹',
	1,
	'挂起',
	0,
	'查询',
	0,
	'审核',
	0,
	'加签',
	0,
	'会签',
	0,
	'流转自定义',
	0,
	'公文',
	0,
	'重要性',
	0,
	'分配',
	0,
	'关注',
	0,
	'确认',
	0,
	'列表',
	1,
	'批量审核',
	0,
	0,
	'',
	0,
	0,
	0,
	0,
	0,
	'',
	'',
	NULL,
	'审核信息',
	1,
	0,
	'',
	0,
	1,
	1,
	0,
	'审核',
	'同意',
	0,
	1,
	300.00,
	500.00,
	0.00,
	400.00,
	'',
	0,
	0,
	0,
	0,
	'',
	0,
	'$flowName',
	'',
	2.00,
	0,
	0,
	0,
	1.00,
	0,
	0,
	2.00,
	0,
	0,
	0,
	'',
	'',
	4,
	1,
	'',
	'',
	0,
	0,
	0,
	0,
	'',
	0,
	0,
	'',
	'',
	'',
	0,
	12,
	'',
	0,
	'http://',
	0,
	'',
	0,
	0,
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	$x,
	$y,
	'',
	'',
	'',
	'轨迹',
	0,
	5.00,
	5.00,
	300.00,
	400.00,
	'子线程',
	0,
	5.00,
	5.00,
	300.00,
	400.00,
	'子流程',
	0,
	1,
	'启动子流程',
	'',
	5.00,
	5.00,
	300.00,
	400.00,
	'',
	0,
	0,
	'流转自定义',
	0,
	0,
	5.00,
	5.00,
	300.00,
	400.00,
	'打开本地',
	0,
	'打开模板',
	0,
	'保存',
	1,
	'接受修订',
	0,
	'拒绝修订',
	0,
	'套红按钮',
	0,
	1,
	0,
	'打印按钮',
	0,
	'签章按钮',
	0,
	'插入流程',
	0,
	0,
	0,
	'下载',
	0,
	1,
	NULL,
	1,
	0,
	NULL,
	0,
	5,
	'',
	'',
	1,
	0,
	0,
	0,
	'',
	'',
	'',
	'',
	'接受人',
	0,
	'节点时限',
	0,
	'打开本地',
	'打开模板',
	'保存',
	'接受修订',
	'拒绝修订',
	'套红',
	1,
	'打印',
	'签章',
	'插入流程',
	0,
	0,
	0,
	''
) ;

";    
	  Db::execute($sql);

	//查询出当前流程所有的节点并更新到每个节点的GroupStaNDs字段
	$result=Db::table('wf_node')
	->field('NodeID')
	->where('FK_Flow',$param['FK_Flow'])
	->select();
	$str='';
	foreach($result as $value){
		$str=$str.'@'.$value['NodeID'];
	}

	Db::table('wf_node')
	->where('FK_Flow', $param['FK_Flow'])
	->update(['GroupStaNDs' => $str]); 

	//向`sys_frmattachment`表中添加数据

    Db::table('sys_frmattachment')
	->data([
		'MyPK'=>$firstNo.'_FrmWorkCheck',
		'FK_MapData'=>$MaxNode['max(NodeID)'],
		'NoOfObj'=>$firstNo.'_FrmWorkCheck',
		'Name'=>'审核组件',
		'Exts'=>"*.*",
		'SaveTo'=>'/DataUser/UploadFile/',
		'Sort'=>'',
		'X'=>'94.09',
		'Y'=>'333.18',
		'W'=>'626.36',
		'H'=>'150',
		'AtPara'=>'@IsWoEnablePageset=1@IsWoEnablePrint=1@IsWoEnableViewModel=1@IsWoEnableReadonly=0@IsWoEnableSave=1@IsWoEnableWF=1@IsWoEnableProperty=1@IsWoEnableRevise=1@IsWoEnableIntoKeepMarkModel=1@FastKeyIsEnable=0@IsWoEnableViewKeepMark=1@FastKeyGenerRole=@IsWoEnableTemplete=1',
		])
	->insert();

	//向sys_mapattr表中添加数据
	$data = [
		[
			'MyPK' => 'ND'.$firstNo.'_CDT', 
			'FK_MapData' => 'ND'.$firstNo,
			'KeyOfEn' => 'CDT', 
			'Name' => '完成时间',
			'DefVal' => '@RDT', 
			'UIContralType' => 0,
			'MyDataType' => 7, 
			'LGType' => 0,
			'UIWidth' => 145, 
			'UIHeight' => 23,
			'MinLen' => 0, 
			'MaxLen' => 300,
			'UIBindKey' => '', 
			'UIRefKey' => '',
			'UIRefKeyText' => '', 
			'ExtIsSum' => 0,
			'UIVisible' => 0, 
			'UIIsEnable' => 0,
			'UIIsLine' => 0,
			'UIIsInput' => 0,
			'IsRichText' => 0,
			'IsSupperText' => 0,
			'FontSize' => 0, 
			'IsSigan' => 0,
			'X' => 5, 
			'Y' => 5,
			'GUID' => '', 
			'Tag' => '1',
			'EditType' => 1, 
			'Tip' => '',
			'ColSpan' => 1,
			'GroupID' => 1,
			'IsEnableInAPP' => 1,
			'Idx' => 4,
			'AtPara' => '',
			'GroupIDText' => '0', 
			'DefValText' => '0',
			'RBShowModel' => '0', 
			'IsEnableJS' => '0',
			'ExtDefVal' => '0', 
			'ExtDefValText' => '0',
			'TextColSpan' => 1,
			'RowSpan' => 1
		],
		[
			'MyPK' => 'ND'.$firstNo.'_Emps', 
			'FK_MapData' => 'ND'.$firstNo,
			'KeyOfEn' => 'Emps', 
			'Name' => 'Emps',
			'DefVal' => '', 
			'UIContralType' => 0,
			'MyDataType' => 1, 
			'LGType' => 0,
			'UIWidth' => 100, 
			'UIHeight' => 23,
			'MinLen' => 0, 
			'MaxLen' => 8000,
			'UIBindKey' => '', 
			'UIRefKey' => '',
			'UIRefKeyText' => '', 
			'ExtIsSum' => 0,
			'UIVisible' => 0, 
			'UIIsEnable' => 0,
			'UIIsLine' => 0,
			'UIIsInput' => 0,
			'IsRichText' => 0,
			'IsSupperText' => 0,
			'FontSize' => 0, 
			'IsSigan' => 0,
			'X' => 5, 
			'Y' => 5,
			'GUID' => '', 
			'Tag' => '',
			'EditType' => 1, 
			'Tip' => '',
			'ColSpan' => 1,
			'GroupID' => 1,
			'IsEnableInAPP' => 1,
			'Idx' => 6,
			'AtPara' => '',
			'GroupIDText' => '0', 
			'DefValText' => '0',
			'RBShowModel' => '0', 
			'IsEnableJS' => '0',
			'ExtDefVal' => '0', 
			'ExtDefValText' => '0',
			'TextColSpan' => 1,
			'RowSpan' => 1
		],
		[
			'MyPK' => 'ND'.$firstNo.'_FID', 
			'FK_MapData' => 'ND'.$firstNo,
			'KeyOfEn' => 'FID', 
			'Name' => 'FID',
			'DefVal' => '0', 
			'UIContralType' => 0,
			'MyDataType' => 2, 
			'LGType' => 0,
			'UIWidth' => 100, 
			'UIHeight' => 23,
			'MinLen' => 0, 
			'MaxLen' => 300,
			'UIBindKey' => '', 
			'UIRefKey' => '',
			'UIRefKeyText' => '', 
			'ExtIsSum' => 0,
			'UIVisible' => 0, 
			'UIIsEnable' => 0,
			'UIIsLine' => 0,
			'UIIsInput' => 0,
			'IsRichText' => 0,
			'IsSupperText' => 0,
			'FontSize' => 0, 
			'IsSigan' => 0,
			'X' => 5, 
			'Y' => 5,
			'GUID' => '', 
			'Tag' => '',
			'EditType' => 1, 
			'Tip' => '',
			'ColSpan' => 1,
			'GroupID' => 1,
			'IsEnableInAPP' => 1,
			'Idx' => 2,
			'AtPara' => '',
			'GroupIDText' => '0', 
			'DefValText' => '0',
			'RBShowModel' => '0', 
			'IsEnableJS' => '0',
			'ExtDefVal' => '0', 
			'ExtDefValText' => '0',
			'TextColSpan' => 1,
			'RowSpan' => 1
		],
		[
			'MyPK' => 'ND'.$firstNo.'_FK_Dept', 
			'FK_MapData' => 'ND'.$firstNo,
			'KeyOfEn' => 'FK_Dept', 
			'Name' => '操作员部门',
			'DefVal' => '', 
			'UIContralType' => 0,
			'MyDataType' => 1, 
			'LGType' => 0,
			'UIWidth' => 100, 
			'UIHeight' => 23,
			'MinLen' => 0, 
			'MaxLen' => 50,
			'UIBindKey' => '', 
			'UIRefKey' => '',
			'UIRefKeyText' => '', 
			'ExtIsSum' => 0,
			'UIVisible' => 0, 
			'UIIsEnable' => 0,
			'UIIsLine' => 0,
			'UIIsInput' => 0,
			'IsRichText' => 0,
			'IsSupperText' => 0,
			'FontSize' => 0, 
			'IsSigan' => 0,
			'X' => 5, 
			'Y' => 5,
			'GUID' => '', 
			'Tag' => '',
			'EditType' => 1, 
			'Tip' => '',
			'ColSpan' => 1,
			'GroupID' => 1,
			'IsEnableInAPP' => 1,
			'Idx' => 7,
			'AtPara' => '',
			'GroupIDText' => '0', 
			'DefValText' => '0',
			'RBShowModel' => '0', 
			'IsEnableJS' => '0',
			'ExtDefVal' => '0', 
			'ExtDefValText' => '0',
			'TextColSpan' => 1,
			'RowSpan' => 1
		],
		[
			'MyPK' => 'ND'.$firstNo.'_OID', 
			'FK_MapData' => 'ND'.$firstNo,
			'KeyOfEn' => 'OID', 
			'Name' => 'WorkID',
			'DefVal' => '0', 
			'UIContralType' => 0,
			'MyDataType' => 2, 
			'LGType' => 0,
			'UIWidth' => 100, 
			'UIHeight' => 23,
			'MinLen' => 0, 
			'MaxLen' => 300,
			'UIBindKey' => '', 
			'UIRefKey' => '',
			'UIRefKeyText' => '', 
			'ExtIsSum' => 0,
			'UIVisible' => 0, 
			'UIIsEnable' => 0,
			'UIIsLine' => 0,
			'UIIsInput' => 0,
			'IsRichText' => 0,
			'IsSupperText' => 0,
			'FontSize' => 0, 
			'IsSigan' => 0,
			'X' => 5, 
			'Y' => 5,
			'GUID' => '', 
			'Tag' => '',
			'EditType' => 2, 
			'Tip' => '',
			'ColSpan' => 1,
			'GroupID' => 1,
			'IsEnableInAPP' => 1,
			'Idx' => 1,
			'AtPara' => '',
			'GroupIDText' => '0', 
			'DefValText' => '0',
			'RBShowModel' => '0', 
			'IsEnableJS' => '0',
			'ExtDefVal' => '0', 
			'ExtDefValText' => '0',
			'TextColSpan' => 1,
			'RowSpan' => 1
		],
		[
			'MyPK' => 'ND'.$firstNo.'_RDT', 
			'FK_MapData' => 'ND'.$firstNo,
			'KeyOfEn' => 'RDT', 
			'Name' => '接受时间',
			'DefVal' => '', 
			'UIContralType' => 0,
			'MyDataType' => 7, 
			'LGType' => 0,
			'UIWidth' => 145, 
			'UIHeight' => 23,
			'MinLen' => 0, 
			'MaxLen' => 300,
			'UIBindKey' => '', 
			'UIRefKey' => '',
			'UIRefKeyText' => '', 
			'ExtIsSum' => 0,
			'UIVisible' => 0, 
			'UIIsEnable' => 0,
			'UIIsLine' => 0,
			'UIIsInput' => 0,
			'IsRichText' => 0,
			'IsSupperText' => 0,
			'FontSize' => 0, 
			'IsSigan' => 0,
			'X' => 5, 
			'Y' => 5,
			'GUID' => '', 
			'Tag' => '1',
			'EditType' => 1, 
			'Tip' => '',
			'ColSpan' => 1,
			'GroupID' => 1,
			'IsEnableInAPP' => 1,
			'Idx' => 3,
			'AtPara' => '',
			'GroupIDText' => '0', 
			'DefValText' => '0',
			'RBShowModel' => '0', 
			'IsEnableJS' => '0',
			'ExtDefVal' => '0', 
			'ExtDefValText' => '0',
			'TextColSpan' => 1,
			'RowSpan' => 1
		]
		
	];

	 Db::table('sys_mapattr')->insertAll($data);

	//向sys_mapdata表中添加一条数据
	Db::table('sys_mapdata')
	->data([
		'No'=>'ND'.$firstNo,
		'Name'=>$Name,
		'PTable'=>'ND'.$param['FK_Flow'].'Rpt',
		'AtPara'=>'@IsHaveCA=0',
		])
	->insert();

    //修改`sys_serial`的OID字段

        $jieguo['NodeID'] =$firstNo;
		$jieguo['Name'] =$Name;
		return $jieguo;
	}
	//连接线删除
	public function Direction_Delete(){
		$param=$this->request->param();
		$where=[];

		$where['FK_Flow']=['=',$param['FK_Flow']];
		$where['Node']=['=',$param['FK_Node']];
		$where['ToNode']=['=',$param['ToNode']];

		Db::table('wf_direction')
		->where($where)
		->delete();

		return "@删除成功";
	}
	//撤回流程初始化
	public function Return_Init(){
		$param=$this->request->param();
		//查询当前节点的上一个节点以及上一个节点的Name
		$data=Db::table('wf_direction')
		->where('ToNode',$param['FK_Node'])
		->find();

		$Node=Db::table('wf_node')
		->field('Name')
		->where('NodeID',$data['Node'])
		->find();

		


	}
	//删除节点
	public function DeleteNode(){
		$param=$this->request->param();
	   //删除在`sys_mapattr`表中对应的数据
	   $where['MyPK']=['=','ND'.$param['FK_Node'].'_CDT'];
	   $where['MyPK']=['=','ND'.$param['FK_Node'].'_Emps'];
	   $where['MyPK']=['=','ND'.$param['FK_Node'].'_FID'];
	   $where['MyPK']=['=','ND'.$param['FK_Node'].'_FK_Dept'];
	   $where['MyPK']=['=','ND'.$param['FK_Node'].'_OID'];
	   $where['MyPK']=['=','ND'.$param['FK_Node'].'_RDT'];
	   $where['MyPK']=['=','ND'.$param['FK_Node'].'_Rec'];
	   Db::table('sys_mapattr')
	   ->where($where)
	   ->delete();

	   //删除`sys_frmattachment`中的数据
	   Db::table('sys_frmattachment')
	   ->where('MyPK',$param['FK_Node'].'_FrmWorkCheck')
	   ->delete();

	   //删除sys_mapdata中的数据
	   Db::table('sys_mapdata')
	   ->where('No','ND'.$param['FK_Node'])
	   ->delete();

	   //删除wf_node中的数据
	   Db::table('wf_node')
	   ->where('NodeID',$param['FK_Node'])
	   ->delete();

	   return '删除成功.';
	}
	   //流程设计保存
	public function Designer_Save(){
		$param=$this->request->param();
	    
		$shuzu = explode("@", $param['Dirs']);
		//数组去空
		$shuzu=array_filter($shuzu);
		//更新节点之间的连接线信息
		foreach($shuzu as $value){
			$value = explode(",", $value);
			$data=Db::table('wf_direction')
			->where('MyPK',$value[0])
			//->fetchSql(true)
			->find();
		
			if(!empty($data)){
				//不为空则更新
				Db::table('wf_direction')
				->where('MyPK',$value[0])
				->update([
					'FK_Flow'  => $value[1],
					'Node' =>  $value[2],
					'ToNode' =>  $value[3],
				]);
			}else{
				//为空则添加
				Db::table('wf_direction')
				->data([
					'MyPK'  => $value[0],
					'FK_Flow'  => $value[1],
					'Node' =>  $value[2],
					'ToNode' =>  $value[3],
					])
				->insert();
			}
		}
		$shuzu = explode("@", $param['Nodes']);
		//数组去空
		$shuzu=array_filter($shuzu);
		//更新节点之间的连接线信息
		foreach($shuzu as $value){
			$value = explode(",", $value);
				//更新节点位置信息
				Db::table('wf_node')
				->where('NodeID',$value[0])
				->update([
					'X'  => $value[1],
					'Y' =>  $value[2],
				]);
		}

		return "保存成功.";
	}
}
